<?php
$main_page_header = 'location:../registration.html';
if (empty($_POST['login']) or empty($_POST['password1']) or empty($_POST['password2']))
{
	header($main_page_header);
	exit;
}

$login = $_POST['login'];
$reg = '/^[A-Za-z0-9_]{2,}$/';
if (!preg_match($reg, $login))
{
	header($main_page_header);
	exit;
}

if ($_POST['password1'] != $_POST['password2'])
{
	header($main_page_header);
	exit;
}

$password = $_POST['password1'];

mysql_connect('localhost', 'root');
mysql_select_db('dots');
$query = "SELECT userID FROM users WHERE login='$login'";
$result = mysql_query($query);
if (!$result)
{
	header($main_page_header);
	exit;
}

$rows = mysql_fetch_row($result);
if ($rows)
{
	header($main_page_header);
	exit;
}

$query = "INSERT INTO users (login, password) VALUES ('$login', '$password')";
$result = mysql_query($query);
if(!$result)
{
	header($main_page_header);
	exit;
}

header('location:../index.html');
?>
